package cmd

import (
	"app/config"
	"app/internal/bootstrap"
	"github.com/spf13/cobra"
	"log"
)

func init() {
	rootCmd.AddCommand(cronCmd) //队列
}

var cronCmd = &cobra.Command{
	Use:   "cron",
	Short: "start cron work",
	Long:  `app cron -c etc/config.yml`,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		//加载配置
		return config.LoadFromFile(configYml)
	},
	Run: func(cmd *cobra.Command, args []string) {
		log.Printf("【%s】服务启动中", cmd.Name())
		
		bootstrap.StartCron()

		waitForShutdown()

		log.Printf("【%s】服务启动中", cmd.Name())
	},
	PostRunE: func(cmd *cobra.Command, args []string) error {
		return nil
	},
}
